import $V from './$V';
import ma from './ma';

export default function emv(high, low, volume, N, M) {
    let A = $V.add($V.subv(high, 1, high.length), $V.subv(low, 1, high.length));
    let B = $V.add($V.subv(high, 0, high.length - 1), $V.subv(low, 0, high.length - 1));
    let Mid = [0].concat($V.div_constant($V.sub(A, B), 2));
    let Bro = $V.div($V.div_constant(volume, 1000000000), $V.sub(high, low));
    Bro = $V.set_by_index(Bro, $V.where(Bro, '==', Infinity), 0);
    let EM = $V.div(Mid, Bro);
    EM = $V.set_by_index(EM, $V.where(EM, '==', Infinity), 0);
    let EMVValue = ma(EM, N);
    let MAEMVVAlue = ma(EMVValue, M);
    return { EMVValue, MAEMVVAlue };
}
